package com.boxin.ims.modules.wechat.busi;

import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.ims.modules.sys.utils.EncryptUtils;
import com.boxin.ims.modules.wechat.entity.WechatMember;
import com.boxin.ims.modules.wechat.service.WechatMemberService;
import com.thinkgem.jeesite.modules.sys.service.SystemService;

/**
 * @author Jakemanse
 * @date 2014-2-1
 * @function <p> 会员密码服务</p>
 */
@Service
public class PasswordProcessor extends BusinessProcessor{
	
	
	@Autowired
	WechatMemberService wechatMemberService;

	@Override
	public ProcessMessage process() {
		WechatMember member = memberCheckAndReply();
		if(member != null){
			String pwd = getRandPassword();
			
			//String enpwd //= systemService.entryptMD5Pssword(pwd);
			String enpwd = EncryptUtils.MD5EncodeString(pwd);
			member.setPassword(enpwd);
			member.setIsRandomPassword(true);
			
			wechatMemberService.save(member);
			
			writeToUser("您的动态密码是:"+pwd);
		}
		return null;
	}

	@Override
	public boolean isNeedBeMember() {
		return false;
	}
	
	/**
	 * @author Jakemanse
	 * @time 2014-2-1  下午10:53:40
	 * @function <p>  </p>
	 * @return
	 */
	public   String getRandPassword(){
		String pwd = "";
		for(int i=0;i< 6;i++){
			Random random = new Random();
			int pa = random.nextInt(10);
			pwd +=""+pa;
		}
		
		return pwd;
	}
	
	

		
}
